%function f = calibration1980(parameter_vector,XA, XS, XM, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F, Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);
%function f = calibration1980(parameter_vector, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F, Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);
%function f = calibration1980(parameter_vector, xiH0_F, xiH0_C, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F, Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);
function f = calibration1980(parameter_vector, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F, Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);

%parameter_vector_all = [parameter_vector,XA, XS, XM, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F];
%parameter_vector_all = [parameter_vector, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F];
parameter_vector_all = [parameter_vector, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F];


equilibrium = EquilibriumFunction(parameter_vector_all,Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);

VA_A = equilibrium(16);
VA_S = equilibrium(19);
VA_M = equilibrium(20);
l_A = equilibrium(30);  
l_S = equilibrium(28);
l_M = equilibrium(29);
pop_R = equilibrium(31);
pop_F = equilibrium(32);
pop_C = equilibrium(33);
EE_R = equilibrium(34);
EE_U = equilibrium(37);
pi_E_R(1) = equilibrium(42);
pi_E_R(2) = equilibrium(43);
pi_E_R(3) = equilibrium(44);
pi_E_R(4) = equilibrium(45);
pi_E_R(5) = equilibrium(46);
pi_E_U(1) = equilibrium(57);
pi_E_U(2) = equilibrium(58);
pi_E_U(3) = equilibrium(59);
pi_E_U(4) = equilibrium(60);
pi_E_U(5) = equilibrium(61);
pi_E_future(1) = equilibrium(62);
pi_E_future(2) = equilibrium(63);
pi_E_future(3) = equilibrium(64);
pi_E_future(4) = equilibrium(65);
pi_E_future(5) = equilibrium(66);


Dist_VA = sum(([VA_A,VA_S, VA_M]/100-[3.4381,11.2815,85.2803]/100).^2);


Dist_Emp = sum(( [l_A,l_S,l_M]-[25.72, 12.28, 62.00]/100).^2);

      
Dist_pop_1980 = sum(([pop_R, pop_F, pop_C ]-[28.74, 10.69, 60.57 ]/100).^2);


Dist_AverageEduc_RU_1980 = sum(([EE_R,EE_U]-[1.95,5.42]).^2);


Dist_EducGroups_R = sum(([pi_E_R]-[0.4719, 0.4592, 0.0426, 0.0194, 0.0068]).^2);  
    

Dist_EducGroups_U = sum(([pi_E_U]-[0.1483, 0.4617, 0.1677, 0.1277, 0.0945]).^2);  
        
    
Dist_EducGroups_2010 = sum(([pi_E_future]-[0.0916,0.3074, 0.2742, 0.2397, 0.0871]).^2);   
  

%% Workers and Production

Dist_WnP = Dist_VA + Dist_Emp;
%% Population
Dist_Pop = Dist_pop_1980;

%% Education
Dist_EducGroups = Dist_EducGroups_R + Dist_EducGroups_U;

%% 2010
Dist_2010 = Dist_EducGroups_2010;

%% Total
Dist_Total = Dist_EducGroups + Dist_Pop + Dist_WnP;

%f= Dist_Emp + Dist_pop_1980;
f= Dist_Emp + Dist_pop_1980+Dist_VA;
  